package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.BpEmergencyDefect;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface BpEmergencyDefectDao extends JpaRepository<BpEmergencyDefect, Long> {

    List<BpEmergencyDefect> findByRecordId(Long id);

    List<BpEmergencyDefect> findByRecordIdAndCorrect(Long id, String i);

    int countByRecordId(Long id);

    int countByRecordIdAndState(Long id, int i);

    @Modifying
    @Query(value = "UPDATE wwyt_bp_emergency_defect SET delete_flag = '1' WHERE RECORD_ID = ?1", nativeQuery = true)
    void deleteByRecordId(Long id);

    @Modifying
    @Query(value = "UPDATE wwyt_bp_emergency_defect SET delete_flag = '1' WHERE RECORD_ID IN ?1", nativeQuery = true)
    void deleteByRecordIds(List<Long> ids);

    @Modifying
    @Query(value = "UPDATE wwyt_bp_emergency_defect SET delete_flag = '1' WHERE ID IN ?1", nativeQuery = true)
    void deleteByIds(List<Long> defectIds);

    @Query(value = "SELECT ID FROM `wwyt_bp_emergency_defect` WHERE RECORD_ID = ?1 AND DELETE_FLAG = '0'", nativeQuery = true)
    List<Long> findIdsByRecordId(Long id);
}
